﻿#include <QDebug>
#include "qexceldriver.h"

Q_GLOBAL_STATIC(QExcelDriver,excelDriver);

QExcelDriver::QExcelDriver(QObject *parent) : QAxObject(parent)
{
    if(setControl("Excel.Application"))
    {
        setProperty("Visible",false);
        setProperty("Interactive ",false);
        setProperty("DisplayAlerts",false);

        qDebug()<<"\n-------Load Excel Driver Success-----\n"
                <<"Version:"<<dynamicCall("Version").toString()<<"\n"
                <<"Path:"<<dynamicCall("Path").toString()<<"\n";

        m_excelWorkbooks = querySubObject("Workbooks");

    }else{
        qCritical()<<__FUNCTION__<<": Unable to load the Excel driver";
    }
}

QExcelDriver::~QExcelDriver()
{

}

QExcelDriver *QExcelDriver::instance()
{
    return excelDriver;
}

QAxObject *QExcelDriver::openWorkbook(QString filePath)
{
    if(m_excelWorkbooks){
        return m_excelWorkbooks->querySubObject("Open(QString &filePath)",filePath);
    }else{
        return nullptr;
    }
}

QAxObject *QExcelDriver::addWorkbook()
{
    if(m_excelWorkbooks){
        return m_excelWorkbooks->querySubObject("Add()");
    }else{
        return nullptr;
    }
}
